/**
 * zmn组织模块-组织编辑
 * 文件命名格式：zmn.模块名称.表/功能.js
 * @author heguanghua
 * @since 2020/04/24 14:11
 */
layui.define(['form', 'layedit', 'zmnApp', 'laydate'], function (exports) {
    let $ = layui.$;
    let form = layui.form;
    let layer = layui.layer;
    let zmnApp = layui.zmnApp;

    form.render(null, "zmn-form");

    // 提交
    form.on('submit(zmn-form-submit)', function(obj){
        let data = obj.field;
        let url = zmnApp.SYS_BASE_URL +"/organize/modify/addEdit.action";
        let jumpStop = false;
        $.ajax({
            async: false,
            type: "POST", url: url,
            contentType: "application/json", dataType: "json", data: JSON.stringify(data),
            success:function(json) {
                let message = json.status == zmnStatus.SUCCESS ? "操作成功！" : json.message;
                layer.msg(message);
                if(json.status == zmnStatus.SUCCESS && !zmnUtil.isNotZeroInteger(data.orgId)) {
                    zmnPage.direct(zmnApp.SYS_BASE_URL +"/organize/detail.action?orgId=" + json.data, 0);
                } else if(json.status == zmnStatus.FAIL) {
                    jumpStop = true;
                }
                return;
            },
            error:function(XMLHttpRequest, torganizeStatus, errorThrown){}
        })
        if(jumpStop || data.orgId * 1 > 0) {
            return false;
        }
    });
    
    //对外暴露的接口
    exports('organize_detail', {});
});